import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/common/images_url.dart';
import 'package:ty_smart_watch/route/routes.dart';

import '../../../utils/Log.dart';

class DataList extends StatelessWidget {
  final int id;
  const DataList({super.key, required this.id});

  @override
  Widget build(BuildContext context) {
    return
        // Obx(
        //     () =>
        Expanded(
            child: Container(
      color: Color(0xFFEBEBEB),
      child: ListView.builder(
        itemCount: 5,
        // itemCount: controller.deviceListList.length,
        scrollDirection: Axis.vertical,
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              Log.d("跳转呀 $index");
              Get.toNamed(Routes.sportDetailSecondPage,arguments: {"id":id});
            },
            child: DataItem(),
          );
        },
      ),
    ));
    // ),
  }
}

class DataItem extends StatelessWidget {
  var style1 = TextStyle(fontSize: 14, color: Colors.grey);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(10),
      decoration: const BoxDecoration(
          //圆角半径
          borderRadius: BorderRadius.all(Radius.circular(12.0)),
          boxShadow: [
            BoxShadow(color: Colors.grey, offset: Offset(0, 0), blurRadius: 8, spreadRadius: 0),
          ],
          color: Colors.white),
      child: Column(
        children: [
          //第一行
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text("2024/07", style: TextStyle(fontSize: 18)),
              Image.asset(ICON_CHILD_MONTH_ARROW, width: 16, height: 16),
            ],
          ),
          //第二行
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Expanded(child: Text("2公里", style: style1, textAlign: TextAlign.left)),
              Expanded(child: Text("08分07秒", style: style1, textAlign: TextAlign.center)),
              Expanded(child: Text("2次", style: style1, textAlign: TextAlign.center)),
              Expanded(child: Text("0千卡", style: style1, textAlign: TextAlign.right)),
            ],
          ),
          SizedBox(height: 6),
          Container(
            color: Color(0xFFEBEBEB),
            child: ListView.builder(
              //解决无限高度问题
              shrinkWrap: true,
              //禁用滑动事件
              physics: const NeverScrollableScrollPhysics(),

              itemCount: 5,
              // itemCount: controller.deviceListList.length,
              scrollDirection: Axis.vertical,
              itemBuilder: (context, index) {
                return ChildDataItem();
              },
            ),
          ),
        ],
      ),
    );
  }
}

class ChildDataItem extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        color: Colors.white,
        child: Column(
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.center, // 设置纵轴对齐方式为顶部对齐
              children: [
                Image.asset(WATCH_SETTING, width: 32, height: 32),
                const SizedBox(width: 6),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      //第一行
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("跑步", textAlign: TextAlign.start),
                          Text("07月15日", textAlign: TextAlign.right),
                        ],
                      ),
                      //第二行
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("2024/07"),
                          Text("2公里"),
                          Text("2公里"),
                          Text("2公里"),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
            Container(width: double.infinity, height: 0.5, color: Colors.grey),
            const SizedBox(height: 6),
          ],
        ));
  }
}
